import axios from 'axios'

export function request(config) {
  const instance = axios.create({
    baseURL: 'http://123.207.32.32:8000', // url = base url + request url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 5000 // request timeout
  })
  // response interceptor
  instance.interceptors.response.use(

    response => {
      const res = response.data
      //判断一下返回结果是不是ok
      if (
        res.result ||
        res.result === true ||
        res.result == 'OK' ||
        res.result == 'ok' ||
        response.status == 200
      ) {
        return res
      } else {
        return res
      }
    },
    error => {
      console.log('err' + error) // for debug
      return Promise.reject(error)
    }
  )
  return instance(config)
}
